
#include <pthread.h>
#include "Mutex.h"

Mutex::Mutex () {
 pthread_mutex_init (&mutexInfo, NULL);
}

bool Mutex::lock (bool block) {
 if (block) {
  pthread_mutex_lock (&mutexInfo);
  return true;
 }
 else {
  if (pthread_mutex_trylock (&mutexInfo) == 0) {
   return true;
  } else {
   return false;
  }
 }
}

void Mutex::unlock () {
 pthread_mutex_unlock (&mutexInfo);
}

pthread_mutex_t* Mutex::c_mutex() {
 return &mutexInfo;
}

Mutex::~Mutex() {
 pthread_mutex_destroy (&mutexInfo);
}
